

Public Class frmChitmemberStatusSelector

    Private ptrMember As cmplib01.ChitMember
    Private ptrGame As cmplib01.CampaignerGameData

    Private eNames() As String
    Private eValues() As Integer

    Private previousStatus As cmplib01.GroundUnitStatus_cgd
    Private newStatus As cmplib01.GroundUnitStatus_cgd


    Public Shadows Sub showdialog(ByRef game As cmplib01.CampaignerGameData, ByRef member As cmplib01.ChitMember)
        Try
            ptrMember = member
            ptrGame = game

            '// populate available statusus...
            eNames = [Enum].GetNames(GetType(cmplib01.GroundUnitStatus_cgd))
            eValues = [Enum].GetValues(GetType(cmplib01.GroundUnitStatus_cgd))

            For Each s As String In eNames
                cboStatus.Items.Add(s.Replace("_", ""))
            Next

            '// find the status of the selected item and display it.
            previousStatus = member.Status
            newStatus = member.Status

            For i As Integer = 0 To eValues.GetUpperBound(0)
                If eValues(i).Equals(member.Status) Then
                    cboStatus.SelectedIndex = i
                    Exit For
                End If
            Next

        Catch ex As Exception
            HandleException("frmChitmemberStatusSelector.showDialog", ex)
        End Try

        MyBase.ShowDialog()
    End Sub

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        If Not previousStatus.Equals(newStatus) Then
            '// change the status
            ptrMember.Status = newStatus

            '// log the event
            ptrGame.LogEvents.Add(New cmplib01.CampaignerLogEvent("Item '" & ptrMember.Name & "' status changed to " & newStatus.ToString & " from " & previousStatus.ToString, ptrGame.selectedPlayer.PlayerName, ptrGame.ElapsedTime.ToString, "<none>", cmplib01.EventAuthorityLevel.PublicEvent))
        End If

        Me.Hide()
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.Hide()
    End Sub

    Private Sub cboStatus_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboStatus.SelectedIndexChanged
        newStatus = eValues(cboStatus.SelectedIndex)
    End Sub
End Class


